﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GFE.SharePoint.Attributes;

namespace GFE.SharePoint.Lazy
{
    public static class GFEAttributeExtensions
    {
        public static T GetMEFAttribute<T>(this Type ObjectType)
        {
            System.Reflection.MemberInfo inf = ObjectType;
            object[] attributes;
            attributes =
               inf.GetCustomAttributes(
                    typeof(T), false);

            return (T)attributes.FirstOrDefault();
        }

        public static IEnumerable<T> GetMEFAttributes<T>(this Type ObjectType)
        {
            System.Reflection.MemberInfo inf = ObjectType;
            object[] attributes;
            attributes =
               inf.GetCustomAttributes(
                    typeof(T), false);

            return attributes.Select(x => (T)x).ToList();
        }
    }
}
